package com.kfm.store.mapper;

import com.kfm.store.model.Goods;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface GoodsMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Goods record);

    int insertSelective(Goods record);

    Goods selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Goods record);

    /**
     * fetchType 属性指定懒加载的开启情况 会覆盖掉全局的lazy-loading-enabled
     * FetchType.LAZY --> 开启懒加载
     * FetchType.EAGER --> 积极加载
     * DEFAULT-->跟全局一致
     * @return
     */
    @Select("select * from goods")
    @Results(id = "goodsResult", value = {
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "goodsName", column = "goods_name"),
            @Result(property = "goodsPrice", column = "goods_price"),
            @Result(property = "categoryId", column = "category_id"),
            @Result(property = "repertory", column = "id", one = @One(
                    select = "com.kfm.store.mapper.RepertoryMapper.selectByGid",
                    fetchType = FetchType.EAGER
            ))
    })
    List<Goods> selectAll();

    int updateByPrimaryKey(Goods record);

    List<Goods> selectByCategoryId(Integer cid);
}